<?php $paymentInvoiceTotal = 0; ?>
<table class="datagrid" id="gridPaymentInvoice">
  <thead class="datagrid">
    <tr>
      <th style="width:16px;"></th>
      <th style="width:50px;">Invoice#</th>
      <th style="width:50px;">Date</th>
      <th style="width:50px;">Amount</th>
      <th style="width:16px;"></th>
    </tr>
  </thead>
  <tbody class="datagrid" style="height:100px;">
    <?php foreach($paymentInvoices as $paymentInvoice):?>
    <tr>
      <td>
        <?php if ($void=='N'):?>
        <?php 
          echo 
            link_to(
              '[X]',
              'actionVerifier/verify?task=paymentInvoiceDelete'.
                '&payment_iden='.$paymentInvoice->getPaymentIden().
                '&invoice_iden='.$paymentInvoice->getInvoiceIden().
                '&cancel_callback=paymentDeleteInvoice('.json_encode(array('payment_iden'=>$paymentInvoice->getPaymentIden(),)).',\'\')'.
                '&callback=paymentDeleteInvoice'.
                '&prompt=Delete paid invoice: "'.$paymentInvoice->getInvoiceId().'" with amount '.number_format($paymentInvoice->getAmount(),2).'.'
            );
        ?>
        <?php endif;?>
      </td>
      <td><?php echo $paymentInvoice->getInvoiceId();?>
      </td>
      <td><?php echo $paymentInvoice->getInvoiceDate();?></td>
      <td style="text-align:right;"><?php echo number_format($paymentInvoice->getAmount(),2);?></td>
      <td></td>
    </tr>
    <?php $paymentInvoiceTotal += $paymentInvoice->getAmount();?>
    <?php endforeach;?>
  </tbody>
  <tfoot class="datagrid">
    <tr>
      <td colspan="3" style="text-align:right;">TOTAL INVOICES PAID</td>
      <td style="text-align:right;"><?php echo number_format($paymentInvoiceTotal,2);?></td>
      <td></td>
    </tr>
  </tfoot>
</table>
<?php $paymentInvoiceTotal = 0;?>
<?php foreach($paymentInvoices as $paymentInvoice):?>
  <?php $paymentInvoiceTotal += $paymentInvoice->getAmount();?>
<?php endforeach;?>
<?php if ($void=='N'):?>
<?php if($total_payment>$paymentInvoiceTotal):?>
  <hr/>
  <?php echo $message?$message.'<br>':''?>
  <?php 
    echo 
      link_to(
        'Add Invoice',
        'payment/addInvoice?payment_iden='.$payment_iden.'&customer_iden='.$customer_iden,
        array('id'=>'paymentLinkAddInvoice',)
      );
  ?>
<?php endif;?>
<?php endif;?>

<?php if ($void=='N'):?>
<script language="javascript">
  $(document).ready(
    function(){
      paymentGetGridRowData('<?php echo $payment_iden?>');
      paymentAddInvoice();
      
      $("#gridPaymentInvoice").find('a').click(
        function(e){
          $.get(this.href,{},
            function(content){
              $('#ajPaymentInvoicePanel').show().html(content);
            }
          );
          e.preventDefault();
        }
      );
      
    }
  );
</script>
<?php endif;?>